$(function(){
	$(".coll_body").eq(2).show();
	$(".coll_body").eq(2).children('a').eq(1).addClass("active");
	$(".Collapsing").eq(2).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(2).click(function(){
		$(".Collapsing").eq(2).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(1).toggleClass("active");
	})
//	获取url传值
	function getQueryString(name) {
		var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
		if (result == null || result.length < 1) {return "";}
			return result[1];
		}
		mid = getQueryString("mid");
//	获取维护人员列表信息
	$.ajax({
		type:"post",
		url:serverIP+"/user/maint/list",
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
		success:function (data) {
			let result=data.data.list.result;
			var strVar = "";
			result.map(function(u){
				if(u.maintId==mid){
					$('input[name="name"]').val(u.name);
					username=u.userName;
					$('input[name="userName"]').val(u.userName);
					$('input[name="phone"]').val(u.phone);
					if(u.status==01){
						$('[name="status"] option:first').prop("selected",'selected');
					}else{
						$('[name="status"] option:last').prop("selected",'selected');
					}
					$('input[name="remark"]').val(u.remark);
				}
			})
		}
	})
})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
}
// 手机号码验证
jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
}, "请正确填写您的手机号码");

$.validator.setDefaults({
    submitHandler: function() {
      	var params = $(".form-div").serialize()+'&userName='+username+'&maintId='+mid; 
      	$.ajax( {  
                type : "POST",  
                url : serverIP+"/user/maint/save",  
                data : params,  
                xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
                success : function(data) {
                	if(data.code==0){
                		alert("修改维护人员成功");
                	}else{
                		alert(data.msg);
                	}
                }    
            }); 
    }
});

$(document).ready(function() {
	$('.form-div').validate({
		rules: {
		 	name: "required",
		 	userName: {
		 		required: true,
	        	minlength: 4	
		 	},
		 	phone:{
		 		required: true,
				minlength : 11,
				isMobile : true
		 	},
		},
		messages: {
	      	name: "请输入维护人员的名字",
	      	userName: {
	       		required: "请输入账号名称",
	        	minlength: "用户名至少由4个字母组成"
	      	},
	      	phone: {
	        	required: "请输入维护人员手机号",
	        	minlength: "手机号码长度不正确",
	        	isMobile: "手机号码格式不正确"
	      	},
		}	
	})
	
})
